﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

using EyesOfTheDragon.Events;

using Anthem.GameScreens;

using Anthem.Components;
using EyesOfTheDragon.Globals;
namespace EyesOfTheDragon.Components
{
    public class Lamps :IUpdate, IPauseable
    {
        private const int LampGID = 233;
        private const string triggerLayer = "triggersLayer";
        private const string houseLayer = "HouseLayer";
        public bool Enabled
        {
            get
            {
                return true;
            }
            set { }
        }
        public static Lamps Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Lamps();
                return _instance;
            }
        }

        public void Update(GameTime gt)
        {
            

            
            List<GTile> tiles = map.Instance.getLayer(triggerLayer).getTiles(MapVariables.LampGID);
            foreach( GTile t in tiles)
            {

                if (Player.Instance.Sprite.getRect().Intersects(t.RectPosition))
                {
                    List<GTile> tiles2 = map.Instance.getLayer(houseLayer).getAllTiles();
                    foreach( GTile t2 in tiles2)
                    {
                        if (t2.Position.X == t.Position.X && t2.Position.Y == t.Position.Y)
                        {
                            tiles2.Remove(t2);
                            break;
                        }
                    }
                    map.Instance.getLayer(triggerLayer).getAllTiles().Remove(t);
                   // tiles.Remove(t);
                    Player.Instance.Health += 25;
                    if (Player.Instance.Health > 100)
                        Player.Instance.Health = 100;
                    return;
                }
              
            }
      
           
            
        }
        private static Lamps _instance;
    }
}
